home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / midiplay / midi.txt < prev    next >
Encoding:
Text File  |  1994-05-26  |  3.4 KB  |  69 lines

  1.         
  2.         MCI.VBX - Playing background sound files
  3.  
  4.    This small program demonstrates a method of playing 
  5. midi files in the background using the MCI.VBX custom 
  6. control supplied with Visual Basic 3.0 professional.  The 
  7. MCI control is invisible to the user at all times.  
  8.   The program uses the done event of the MCI custom 
  9. control to play a sequence of midi files.  Options include
  10. disabling sound, skipping a file, and enabling sound. The
  11. current midi file being played is displayed on the bottom
  12. line of the Sound menu option. 
  13.    When the opening form loads, code in the load event 
  14. sets the Sound menu options, initialises a variable "i" to 
  15. 0, sets the first file name to be played and calls the 
  16. Midiplay proceedure from the MCI.Bas file.
  17.    When this file has finished playing, a "done" event is
  18. generated by the MCI custom control.  The variable "i" is 
  19. incremented to 1, which is then processed by the Select 
  20. Case structure, which plays the midi file named in Case 1.
  21. When this file is finished playing, another "done" event 
  22. occurs, the variable "i" is incremented to 2 and the file 
  23. named in Case 2 plays.  In this manner the "done" event 
  24. cycles through the Select Case structure. The last select 
  25. case option (4) replays the first midi file  which started
  26. the cycle, and resets the "i" variable to 0.  This plays 
  27. the second midi file in the cycle when the "done" event 
  28. fires.
  29.    The Select Case Else option is used to end the cycle. 
  30. On the Disable Sound menu, "i" is set to 20, which 
  31. triggers the Select Case Else option, which closes the MCI 
  32. control if it is playing.
  33.    The Enable Sound option from the sound menu starts the 
  34. cycle over again.
  35.    The Midiplay proceedure includes code that tests the 
  36. MCI_PLAYING_MODE. If the user does not have a sound card 
  37. installed in his computer or properly configured for use 
  38. with Windows, a VB error event will not occur crashing
  39. the program but the the Sound options in the menu are 
  40. all greyed out and the string "Midi File: None" appears at 
  41. the bottom of the menu.
  42.    I used the global constants for MCI supplied with the
  43. sample .mak file "Mcitest.mak"(global.bas) which came
  44. with Visual Basic.  The MCI_PLAYING_MODE statement requires
  45. them.
  46.   Note that the form1 Unload event contains code to close
  47. the MMControl if it is open when you exit the program. 
  48.   Although this example uses only Midi files and the Midi 
  49. file sequencer, the examples could easily be changed to 
  50. play Wave files instead by opening the MCI control as a 
  51. Wave player and changing all the Midi files to Wave files.
  52.  
  53.    In my opinion, the MCI.VBX custom control is very 
  54. poorly documented in the Visual Basic manual.  The only
  55. .mak example given shows how to play one sound file at 
  56. a time, by loading a single file from disk, and uses only 
  57. the click events associated with the MMControl to 
  58. manipulate the file. There is some sample code to load a 
  59. single sound file in a form's load event - but no clue as 
  60. to how to process multiple sound files without requiring 
  61. the program's user to either manually load a file or click 
  62. on the VCR type control.   
  63.   This may not be an optimal way of manipulating the 
  64. MCI.vbx custom control but it works!  I've used it in
  65. several applications to play background sound files and it
  66. performs flawlessly.  If anyone knows of a better way to do
  67. this, I would appreciate hearing about it.  I'm a beginner
  68. still learning VB.
  69.